﻿using System;
using System.Collections.Generic;
using System.Text;
using PPAP.Model.Entity;
using System.Data.OracleClient;
using System.Data;

namespace PPAP.DAO
{
    /// <summary>
    /// 数据访问类TESTINGUSER。
    /// </summary>
    public class TESTINGUSERDAO
    {
        public TESTINGUSERDAO()
        { }
        #region  成员方法



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(TESTINGUSER model)
        {
            model.ID = DbHelperOra.GetMaxID("ID", "TESTINGUSER");
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TESTINGUSER(");
            strSql.Append("ID,TESTINGTEAMNAME,TESTINGNAME,TESTINGUSERNAME,PASSWORD,CONTACTTEL)");
            strSql.Append(" values (");
            strSql.Append(":ID,:TESTINGTEAMNAME,:TESTINGNAME,:TESTINGUSERNAME,:PASSWORD,:CONTACTTEL)");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,4),
					new OracleParameter(":TESTINGTEAMNAME", OracleType.VarChar,50),
					new OracleParameter(":TESTINGNAME", OracleType.VarChar,50),
					new OracleParameter(":TESTINGUSERNAME", OracleType.VarChar,50),
					new OracleParameter(":PASSWORD", OracleType.VarChar,50),
					new OracleParameter(":CONTACTTEL", OracleType.VarChar,50)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.TESTINGTEAMNAME;
            parameters[2].Value = model.TESTINGNAME;
            parameters[3].Value = model.TESTINGUSERNAME;
            parameters[4].Value = model.PASSWORD;
            parameters[5].Value = model.CONTACTTEL;

           return  DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(TESTINGUSER model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TESTINGUSER set ");
            strSql.Append("ID=:ID,");
            strSql.Append("TESTINGTEAMNAME=:TESTINGTEAMNAME,");
            strSql.Append("TESTINGNAME=:TESTINGNAME,");
            strSql.Append("TESTINGUSERNAME=:TESTINGUSERNAME,");
            strSql.Append("PASSWORD=:PASSWORD,");
            strSql.Append("CONTACTTEL=:CONTACTTEL");
            strSql.Append(" where id= "+model.ID);
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,4),
					new OracleParameter(":TESTINGTEAMNAME", OracleType.VarChar,50),
					new OracleParameter(":TESTINGNAME", OracleType.VarChar,50),
					new OracleParameter(":TESTINGUSERNAME", OracleType.VarChar,50),
					new OracleParameter(":PASSWORD", OracleType.VarChar,50),
					new OracleParameter(":CONTACTTEL", OracleType.VarChar,50)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.TESTINGTEAMNAME;
            parameters[2].Value = model.TESTINGNAME;
            parameters[3].Value = model.TESTINGUSERNAME;
            parameters[4].Value = model.PASSWORD;
            parameters[5].Value = model.CONTACTTEL;

           return DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(TESTINGUSER model)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TESTINGUSER ");
            strSql.Append(" where id="+model.ID);
            OracleParameter[] parameters = {
};

           return DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TESTINGUSER GetModel(string TESTINGUSERNAME)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,TESTINGTEAMNAME,TESTINGNAME,TESTINGUSERNAME,PASSWORD,CONTACTTEL from TESTINGUSER ");
            strSql.Append(" where TESTINGUSERNAME='"+TESTINGUSERNAME+"'");
            OracleParameter[] parameters = {
};

            TESTINGUSER model = new TESTINGUSER();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                model.TESTINGTEAMNAME = ds.Tables[0].Rows[0]["TESTINGTEAMNAME"].ToString();
                model.TESTINGNAME = ds.Tables[0].Rows[0]["TESTINGNAME"].ToString();
                model.TESTINGUSERNAME = ds.Tables[0].Rows[0]["TESTINGUSERNAME"].ToString();
                model.PASSWORD = ds.Tables[0].Rows[0]["PASSWORD"].ToString();
                model.CONTACTTEL = ds.Tables[0].Rows[0]["CONTACTTEL"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,TESTINGTEAMNAME,TESTINGNAME,TESTINGUSERNAME,PASSWORD,CONTACTTEL ");
            strSql.Append(" FROM TESTINGUSER ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "TESTINGUSER";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}
